package dk.modified.reshary;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;

import dk.modified.reshary.GlobalState.TrackerName;

public class ReportActivity extends Activity {

	EditText report_text;
	Spinner spn_report_category;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_report);
	    Tracker t = ((GlobalState) getApplication()).getTracker(
		        TrackerName.APP_TRACKER);
		    t.setScreenName("Reshary Report");
		    t.send(new HitBuilders.AppViewBuilder().build());
		String title = getResources().getString(R.string.title_activity_report);
		getActionBar().setDisplayHomeAsUpEnabled(true);
		Util.setActionBar(this, title);

		report_text = (EditText) findViewById(R.id.report_text);
		spn_report_category = (Spinner) findViewById(R.id.spn_report_category);

	}

	public void reportButtonOnClick(View v) {

		String category = spn_report_category.getSelectedItem().toString();
		String text = report_text.getText().toString();

		if (text.length() >= 30) {
			Intent returnIntent = new Intent();
			returnIntent.putExtra("issue", category);
			returnIntent.putExtra("reason", report_text.getText().toString());
			setResult(RESULT_OK, returnIntent);
			finish();
		} else {
			String toastText = getResources().getString(
					R.string.report_guide_text);
			Toast.makeText(this, toastText, Toast.LENGTH_LONG).show();
		}

	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    if (item.getItemId() == android.R.id.home) {
	        finish();
	        return true;
	    }
	    return super.onOptionsItemSelected(item);
	}
}
